package com.jse.service;

import java.util.Map;
import java.util.concurrent.ConcurrentMap;

import com.github.benmanes.caffeine.cache.Cache;

public class CacheService {
	
	Cache<Object, Object> cache;

	public CacheService(Cache<Object, Object> cache) {
		this.cache=cache;
	}
	
	public ConcurrentMap<Object, Object> get() {
		return cache.asMap();
	}
	public Object get(Object key) {
		return cache.getIfPresent(key);
	}

	public void set(Object key,Object val) {
		cache.put(key, val);
	}
	public void put(Object key,Object val) {
		cache.put(key, val);
	}
	public void putAll(Map<?, ?> map) {
		cache.putAll(map);
	}
	
	public void remove(Object key) {
		cache.invalidate(key);
	}
	public void delete(Object key) {
		cache.invalidate(key);
	}
	public void del(Object key) {
		cache.invalidate(key);
	}
	public void clear() {
		cache.invalidateAll();
	}
	public boolean isKey(Object key) {
		return cache.getIfPresent(key)!=null;
	}
	public boolean containsKey(Object key) {
		return cache.getIfPresent(key)!=null;
	}
}
